﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WxPayAPI;

namespace HLDM.Website.Wap.weijf.example
{
    public partial class GetAuthInfo : System.Web.UI.Page
    {
        public string msg = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessTokenV2();
                    if (!string.IsNullOrEmpty(jsApiPay.openid))
                    {
                        string redirect_url = Request.QueryString["redirect_url"];
                        string openid = jsApiPay.openid;
                        string url = redirect_url + "&openid=" + openid;
                        Log.Debug(this.GetType().ToString(), "Will Redirect to URL : " + url);
                        Response.Redirect(url);
                    }
                }
                catch (Exception ex)
                {
                    msg = @"<div class=""weui_msg"">
                                <div class=""weui_opr_area"">
                                    <span class=""weui_icon_warn""></span>
                                    微信支付服务繁忙，请重试
                                </div>
                            </div>";

                    Response.Write(msg);
                }
            }
        }
    }
}
